package com.gitee.cui.client.builder;

import com.gitee.cui.client.client.ClientSession;
import com.gitee.cui.common.common.bean.ChatMsg;
import com.gitee.cui.common.common.bean.User;
import com.gitee.cui.common.common.bean.msg.ProtoMsg;

/**
 * 聊天消息构建器
 * @author cuiqingqiang
 * @version 1.0
 * @date 2021/10/27 15:26
 **/
public class ChatMsgBuilder extends BaseBuilder {

    private ChatMsg chatMsg;

    private User user;

    public ChatMsgBuilder (ChatMsg chatMsg, User user, ClientSession session) {
        super(ProtoMsg.HeadType.MESSAGE_REQUEST, session);
        this.chatMsg = chatMsg;
        this.user = user;
    }

    /**
     * 构建消息发送请求
     * @return 消息发送请求
     */
    public ProtoMsg.Message build() {
        ProtoMsg.Message message = buildCommon(-1);
        ProtoMsg.MessageRequest.Builder mb = ProtoMsg.MessageRequest.newBuilder();

        chatMsg.fillMsg(mb);
        return message.toBuilder().setMessageRequest(mb).build();
    }

    /**
     * 获取消息发送请求
     * @param chatMsg 聊天消息
     * @param user 用户信息
     * @param session session信息
     * @return 消息发送请求
     */
    public static ProtoMsg.Message buildChatMsg(ChatMsg chatMsg, User user, ClientSession session) {
        ChatMsgBuilder chatMsgBuilder = new ChatMsgBuilder(chatMsg, user, session);
        return chatMsgBuilder.build();
    }
}
